package iscte.ai.kcgtd;

import java.io.Serializable;
import java.util.Calendar;

import android.text.format.Time;

public class KCGTDTime implements Serializable {

	private static final long serialVersionUID = 1L;
	private int second;
	private int minute;
	private int hour;
	private int monthDay;
	private int month;
	private int year;
	
	public KCGTDTime() {
		Calendar c = Calendar.getInstance();
		String date = Utils.FormatDateTime(c);
        second = c.get(Calendar.SECOND);
		minute = Integer.valueOf(date.split(":")[1]);
		hour = Integer.valueOf(date.split(":")[0]);
		monthDay = c.get(Calendar.DAY_OF_MONTH);
		month = c.get(Calendar.MONTH);
		year = c.get(Calendar.YEAR);
	}
	
	public KCGTDTime(KCGTDTime time) {
		second = time.getSecond();
		minute = time.getMinute();
		hour = time.getHour();
		monthDay = time.getMonthDay();
		month = time.getMonth();
		year = time.getYear();
	}
	
	public KCGTDTime(int monthDay, int month, int year){
		this.monthDay = monthDay;
		this.month = month;
		this.year = year;

		Calendar c = Calendar.getInstance();
        String date = Utils.FormatDateTime(c);
		second = c.get(Calendar.SECOND);
		minute = Integer.valueOf(date.split(":")[1]);
		hour = Integer.valueOf(date.split(":")[0]);
	}
	
	public KCGTDTime(int second, int minute, int hour, int monthDay, int month, int year) {
		this.second = second;
		this.minute = minute;
		this.hour = hour;
		this.monthDay = monthDay;
		this.month = month;
		this.year = year;
	}
	
	public int getSecond() {
		return second;
	}

	public void setSecond(int second) {
		this.second = second;
	}

	public int getMinute() {
		return minute;
	}

	public void setMinute(int minute) {
		this.minute = minute;
	}

	public int getHour() {
		return hour;
	}

	public void setHour(int hour) {
		this.hour = hour;
	}

	public int getMonthDay() {
		return monthDay;
	}

	public void setMonthDay(int monthDay) {
		this.monthDay = monthDay;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}
	
	public boolean isBefore(KCGTDTime time){
		Time current = new Time();
		current.set(this.second, this.minute, this.hour, this.monthDay, this.month, this.year);
		
		Time newTime = new Time();
		newTime.set(time.getSecond(), time.getMinute(), time.getHour(), time.getMonthDay(), time.getMonth(), time.getYear());
		
		return current.before(newTime);
	}
	
	public boolean isAfter(KCGTDTime time){
		Time current = new Time();
		current.set(this.second, this.minute, this.hour, this.monthDay, this.month, this.year);
		
		Time newTime = new Time();
		newTime.set(time.getSecond(), time.getMinute(), time.getHour(), time.getMonthDay(), time.getMonth(), time.getYear());
		
		return current.after(newTime);
	}
	
	public boolean isEquals(KCGTDTime time){
		Time current = new Time();
		current.set(this.second, this.minute, this.hour, this.monthDay, this.month, this.year);
		
		Time newTime = new Time();
		newTime.set(time.getSecond(), time.getMinute(), time.getHour(), time.getMonthDay(), time.getMonth(), time.getYear());
		
		return Time.compare(current, newTime) == 0;
	}
	
	public boolean isSameDay(KCGTDTime time){
		if(this.monthDay == time.getMonthDay() && this.month == time.getMonth() && this.year == time.getYear())
			return true;
		else
			return false;

	}
	
	public void normalize(boolean ignoreDst){
		Time aux = new Time();
		aux.set(this.getSecond(), this.getMinute(), this.getHour(), this.getMonthDay(), this.getMonth(), this.getYear());
		aux.normalize(ignoreDst);
		
		this.setSecond(aux.second);
		this.setMinute(aux.minute);
		this.setHour(aux.hour);
		this.setMonthDay(aux.monthDay);
		this.setMonth(aux.month);
		this.setYear(aux.year);
		
	}

	@Override
	public String toString() {
		return seeDay() + " - " + seeHour();
	}
	
	public String seeDay(){
		return monthDay+"/"+month+"/"+year;
	}
	
	public String seeHour(){
		String h = "";
		String m = "";
		
		if(hour < 10)
			h = "0" + hour;
		else
			h = "" + hour;
		
		if(minute < 10)
			m = "0" + minute;
		else
			m = "" + minute;
			
		return h + ":" + m;
	}
	
}
